package com.itheima.demo2;

import java.io.*;

/*
D盘中创建两个文件夹：itheima-file， itheima-img

在itheima-file中放置多个文件(含图片文件)，将itheima-file中的所有图片文件使用字节流复制到itheima-img中
 */
public class Demo2 {
    public static void main(String[] args) throws IOException {
        //遍历的源文件夹路径
        String source = "D:\\test\\itheima-file";
        //拷贝的目标文件夹路径
        String dest = "D:\\test\\itheima-file";
         File file = new File("D:\\test\\itheima-file");



        String[] list = file.list();

        for (String s : list) {
            if (s.endsWith(".JPEG")) {
                System.out.println(s);
                String name=source+"\\"+s.toString();

                FileInputStream fis = new FileInputStream(name);

                String names="D:\\test\\itheima-img"+"\\"+s.toString();
                FileOutputStream fos = new FileOutputStream(names);

                byte[] buf = new byte[1024];
                int l = -1;
                while ((l = fis.read(buf)) != -1) {
                    fos.write(buf, 0, l);
                }

                fis.close();
                fos.close();
            }
        }

    }
}
